package test.udp.multicast;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.SocketException;

public class MultiClient {
	public static void main(String args[]) {
		try {
			// 创建Socket
			MulticastSocket socket = new MulticastSocket();
			InetAddress group = InetAddress.getByName("231.0.0.0");
			
			// 创建发送数据包
			byte[] dummy = new byte[0];
			DatagramPacket sendPackage = new DatagramPacket(dummy, 0, group, 10000);
			
			// 发送数据
			for (int i = 0; i < 5; i++) {
				byte[] buffer = ("Data line " + i).getBytes();
				sendPackage.setData(buffer);
				sendPackage.setLength(buffer.length);
				socket.send(sendPackage);
			}
			socket.close();

		} catch (SocketException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
